#{extends '/include/main.html' /}
<div class="form-page">
	<a href="@@{TableRelationController.list()}" class="form-backto-result-button">返回</a>
	#{if relation}
		<form action="@@{TableRelationController.delete()}?x-http-method-override=DELETE" method="POST" class="delete-form">
			<input type="hidden" name="relationId" value="${relation.id}" />
			<input type="submit" value="删除" class="form-submit-zone-submit-button"/>
		</form>
	#{/if} 
	<h2 class="form-title">表关系管理</h2>
	#{if relation}
		<form action="@@{TableRelationController.update}?x-http-method-override=PUT" method="POST">
		<input type="hidden" name="relationId" value="${relation.id}" />
	#{/if} 
	#{else}
		<form action="@@{TableRelationController.save}" method="POST">
	#{/else}
		<table class="form-submit-zone">
			<tbody>
				<tr>
					<th>源表表名 </th>
					<td>
						<select name="srcTableId">
							<option value="">请选择</option>
							#{list items:srcTables, as : 'table'}
								<option value="${table.id}" #{if (flash.srcTableId == table.id.toString()) || (flash.srcTableId != '' && relation && relation.srcTable.id == table.id)}selected#{/if}>${table.name}</option>
							#{/list}
						</select>
						<div class="error"><span>#{error 'srcTableId' /}</span></div>
					</td>
				</tr>
				<tr>
					<th>目标表名</th>
					<td>
						<select name="targetTableId">
							<option value="">请选择</option>
							#{list items:targetTables, as : 'table'}
								<option value="${table.id}" #{if (flash.targetTableId == table.id.toString()) || (flash.targetTableId != '' && relation && relation.targetTable.id == table.id)}selected#{/if}>${table.name}</option>
							#{/list}
						</select>
						<div class="error"><span>#{error 'targetTableId' /}</span></div>
					</td>
				</tr>
				<tr>
					<th>关系维护人员</th>
					<td>
						<select name="maintainerId">
							<option value="">请选择</option>
							#{list items:maintainers, as : 'maintainer'}
								<option value="${maintainer.id}" #{if (flash.maintainerId == maintainer.id.toString()) || (flash.maintainerId != '' && relation && relation.maintainer.id == maintainer.id)}selected#{/if}>${maintainer.name}</option>
							#{/list}
						</select>
						<div class="error"><span>#{error 'maintainerId' /}</span></div>
					</td>
				</tr>
				<tr>
					<th>备注</th>
					<td>
						<textarea name="remark">${relation?.remark}</textarea>
					</td>
				</tr>
				<tr>
					<th>提交</th>
					<td>
						<input type="submit" value="提交" class="form-submit-zone-submit-button"/>
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>